﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;

namespace carportal
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sqlConnectionString = ConfigurationManager.ConnectionStrings["bestgifts4usConnectionString"].ConnectionString.ToString();

            //FileInfo file = new FileInfo(Server.MapPath("aspnetdb.sql"));

            string script = TextBox1.Text;
            
            string[] lines = script.Split(new string[] { "GO" + Environment.NewLine } , StringSplitOptions.None);
            SqlConnection conn = new SqlConnection(sqlConnectionString);
            conn.Open();

            SqlCommand sqlcom = new SqlCommand();
            sqlcom.Connection = conn;
            foreach (string line in lines)
            {
                if (line == "")
                {
                }
                else
                {
                    TextBox2.Text = TextBox2.Text + Environment.NewLine + line;
                    sqlcom.CommandText = line;
                    sqlcom.ExecuteNonQuery();
                }
            }
            //file.OpenText().Close();
        }
    }
}